package com.company.servicename.util;

import java.util.Objects;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author fangsong.zhang
 * @date 2019/10/17 17:32
 * Copyright zfs
 * 类说明: 用户工具类
 */
public class UserUtil {
    private UserUtil() {
    }

    /**
     * 获取当前登录用户的数据
     *
     * @return 当前登录用户数据
     */
    public static JwtUser userInfo() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (Objects.isNull(authentication)) {
            return new JwtUser();
        }
        return (JwtUser) authentication.getPrincipal();
    }
}
